/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package graphics.support;

import forhelp.PrintArray;
import java.util.ArrayList;
import org.jfree.chart.plot.Crosshair;

/**
 *
 * @author asus
 */
public class FindCrossHair {

    public static String findclosest(Crosshair X1, Crosshair X2, Crosshair Y1, Crosshair Y2, double[] pos) {
        String var = "";
        int vari = 0;

        ArrayList<Crosshair> a = new ArrayList<>();

        double[] varpos = new double[]{pos[0], pos[0], pos[1], pos[1]};
        a.add(X1);
        a.add(X2);
        a.add(Y1);
        a.add(Y2);
        for (int i = 0; i < a.size() - 1; i++) {

            if (Math.abs(a.get(vari).getValue() - varpos[vari]) <= Math.abs(a.get(i + 1).getValue() - varpos[i + 1])) {

            }

            if (Math.abs(a.get(vari).getValue() - varpos[vari]) > Math.abs(a.get(i + 1).getValue() - varpos[i + 1])) {
                vari = i + 1;

            }

        }

        if (vari == 0) {
            var = "X1";

        }
        if (vari == 1) {
            var = "X2";

        }

        if (vari == 2) {
            var = "Y1";

        }
        if (vari == 3) {
            var = "Y2";

        }
        return var;
    }

}
